package com.desmart.renjiao.announcement;

import android.support.annotation.Nullable;
import android.view.View;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.desmart.renjiao.R;
import com.desmart.renjiao.bean.Announcement;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

public class AnnouncementAdapter extends BaseQuickAdapter<Announcement,AnnouncementAdapter.AnnouncementViewHolder>{

    public AnnouncementAdapter(@Nullable List<Announcement> data) {
        super(R.layout.list_item_announcement_s, data);
    }

    @Override
    protected void convert(AnnouncementViewHolder helper, Announcement item) {

        helper.tvTitle.setText(item.title);
        helper.tvContent.setText(item.body);
        String time = item.releaseTime;
        time = time.substring(0,time.length() -3);
        time = time.replace("/","-");

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
        String format = sdf.format(new Date());
        if (time.startsWith(format)){
            time = time.substring(5);
        }

        helper.tvTime.setText(time);

    }

    class AnnouncementViewHolder extends BaseViewHolder{

        private final TextView tvTitle;
        private final TextView tvContent;
        private final TextView tvTime;

        public AnnouncementViewHolder(View view) {
            super(view);
            tvTitle = view.findViewById(R.id.tv_title);
            tvContent = view.findViewById(R.id.tv_content);
            tvTime = view.findViewById(R.id.tv_time);
        }
    }
}
